package OoDay04.Practice1;

public class PolymorphicDemo {
    public static void main(String[] args) {
        Animal[]animals=new Animal[5];
        animals[0]=new Dog("小黑",1,"黑");
        animals[1]=new Dog("小黄",3,"黄");
        animals[2]=new Chick("小花",1,"黄");
        animals[3]=new Chick("大花",2,"花");
        animals[4]=new Fish("小红",1,"红");
        for (int i=0;i<animals.length;i++){
            animals[i].eat();
            animals[i].drink();
            if (animals[i]instanceof Dog){
                Dog dog=(Dog)animals[i];
                dog.lookHome();
            }
            if (animals[i]instanceof Chick){
                Chick chick=(Chick) animals[i];
                chick.layEggs();
            }
            if (animals[i]instanceof Swim){
                Swim swim=(Swim) animals[i];
                swim.swim();
            }
        }

        Master master=new Master();
        Dog dog=new Dog("小黑",2,"黑");
        master.feed(dog);     //系统自动向上造型
        Chick chick=new Chick("小花",1,"花");
        master.feed(chick);
        Fish fish=new Fish("小红",1,"红");
        master.feed(fish);

    }
}
